package com.tobby.camel.camelinaction.chapter4.bean;

import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.test.junit4.CamelTestSupport;
import org.junit.Test;

public class InvokeWithProcessorTest extends CamelTestSupport {

	@Override
	public RouteBuilder createRouteBuilder() {
		return new RouteBuilder() {

			@Override
			public void configure() throws Exception {
				from("direct:hello").process(new Processor() {

					@Override
					public void process(Exchange exchange) throws Exception {
						String name = exchange.getIn().getBody(String.class);
						HelloBean hello = new HelloBean();
						String answer = hello.hello(name);
						exchange.getOut().setBody(answer);
					}
				});
			}
		};
	}

	@Test
	public void testInvokeWithProcessor() {
		String reply = template.requestBody("direct:hello", "Camel in Action",
				String.class);
		assertEquals("Hello Camel in Action", reply);
	}

}
